<!DOCTYPE html>
<html>
	<head>
		<include file="public:meta" />
		<link rel="stylesheet" href="../public/css/members.css">
	</head>
	<body>
		<include file="public:header" />
		<div class="qs-top-nav x2 list_height">
			<div class="n-cell" onclick="javascript:location.href='{:U('Members/login')}'">账号密码登录<div class="b-line"></div></div>
			<if condition="C('qscms_sms_open') eq 1"><div class="n-cell active">手机动态码登录<div class="b-line"></div></div></if>
			<div class="clear"></div>
		</div>
		<div class="split-block"></div>
		<form action="post" id="logingForm">
			<div class="loging-input-group">
				<div class="group-list mobile">
					<input id="mobile" name="mobile" type="text" class="l-input font14" placeholder="请输入手机号码" autocomplete="off">
					<a href="javascript:;" id="getVerfyCode" class="qs-btn qs-btn-inline qs-btn-medium qs-btn-border-gray font14">获取验证码</a>
				</div>
				<div class="group-list verfy">
					<input id="verfy_code" name="mobile_vcode" type="text" class="l-input font14" placeholder="请输入手机验证码" autocomplete="off">
				</div>
			</div>
			<div class="l-tool-bar list_height">
				<div class="for-pwd link_gray6"><a href="{:U('members/user_getpass')}">忘记密码</a></div>
				<div class="clear"></div>
			</div>
			<div id="pop" style="display:none"></div>
		</form>
		<div class="btn-spacing"><a id="loginBtn" href="javascript:;" class="qs-btn qs-btn-blue font18">验证并登录</a></div>
		<div class="qs-center"><a href="{:U('members/register')}" class="qs-btn qs-btn-inline qs-btn-medium qs-btn-border-orange font14">立即注册</a></div>
		<notempty name="oauth_list">
			<if condition="!(count($oauth_list) eq 1 AND array_key_exists('weixin',$oauth_list))">
				<div class="qs-center coop-title">使用合作账号登录/注册</div>
			</if>
		</notempty>
		<div class="coop-group g3 qs-center">
			<volist name="oauth_list" id="oauth">
			<if condition="$key neq 'weixin'">
				<a href="{:U('callback/index',array('mod'=>$key,'type'=>'login'))}" class="coop-cell">
					<div class="img {$key}"></div>
					<p>{$oauth.name}</p>
				</a>
			</if>
			</volist>
			<div class="clear"></div>
		</div>
		<input type="hidden" id="verifyLogin" value="{$verify_userlogin}">
		<input type="hidden" id="doType" value="1">
		<include file="public:footer" />
		<include file="public:footer_min" />
	</body>
	<script src="http://static.geetest.com/static/tools/gt.js"></script>
	<script>
		/**
		 * 配置极验
		 */
		$.ajax({
			url: qscms.root+'?m=Mobile&c=Captcha&type=mobile&t=' + (new Date()).getTime(),
			type: 'get',
			dataType: 'json',
			success: function(config) {
				initGeetest({
					gt: config.gt,
					challenge: config.challenge,
					offline: !config.success
				}, function(captchaObj) {
					captchaObj.appendTo("#pop");
					captchaObj.onSuccess(function() {
						var doType = eval($('#doType').val()); // 判断是发送手机验证码还是登录
						doType ? doAjax() : sendVerfy();
					});
					window.captchaObj = captchaObj
				});
			}
		});

		/**
		 * 发送手机验证码
		 */
		function sendVerfy() {
			var mobileValue = $.trim($('input[name=mobile]').val());
			$.ajax({
				url: "{:U('Members/reg_send_sms')}",
				cache: false,
				async: false,
				type: 'post',
				dataType: 'json',
				data: { sms_type: 'login', mobile: mobileValue,geetest_challenge: $("input[name='geetest_challenge']").val(),geetest_validate: $("input[name='geetest_validate']").val(),geetest_seccode: $("input[name='geetest_seccode']").val()},
				success: function(result) {
					$('#pop').hide();
					qsToast({type:2,context: result.msg});
					if (result.status) {
						// 开始倒计时
						var countdown = 180;
						function settime() {
							if (countdown == 0) {
								$('#getVerfyCode').removeClass('qs-btn-border-disabled');
								$('#getVerfyCode').text('获取验证码');
								countdown = 180;
								return;
							} else {
								$('#getVerfyCode').addClass('qs-btn-border-disabled');
								$('#getVerfyCode').text('重新发送' + countdown + '秒');
								countdown--;
							}
							setTimeout(function() {
								settime()
							},1000)
						}
						settime();
					} else {
						$('#pop').hide();
						qsToast({type:2,context: result.msg});
					}
				}
			});
		}

		/**
		 * ajax 登录
		 */
		function doAjax() {
			$.ajax({
				url: "{:U('Members/login')}",
				type: 'POST',
				dataType: 'json',
				data: $('#logingForm').serialize(),
				success: function(result) {
					if (result.status) {
						window.location.href = result.data;
					} else {
						$('#pop').hide();
						if (result.data) {
							$("#verifyLogin").val(result.data);
						}
						qsToast({type:2,context: result.msg});
					}
				},
				error: function(result) {
					$('#pop').hide();
					qsToast({type:2,context: result.msg});
				}
			})
		}

		var regularMobile = /^13[0-9]{9}$|14[0-9]{9}$|15[0-9]{9}$|18[0-9]{9}$|17[0-9]{9}$/;
		/**
		 * 发送手机验证码
		 */
		$('#getVerfyCode').on('click', function() {
			if ($(this).hasClass('qs-btn-border-disabled')) return false;
			var mobileValue = $.trim($('input[name=mobile]').val());
			if (mobileValue == '') {
				qsToast({type:2,context: '请输入手机号码'});
				return false;
			}
			if (mobileValue != "" && !regularMobile.test(mobileValue)) {
				qsToast({type:2,context: '手机号码格式不正确'});
				return false;
			}
			$('#doType').val('0'); // 通知极验发送验证码
			window.captchaObj.refresh();
			$('#pop').show();
		})

		/**
		 * 登录验证
		 */
		$('#loginBtn').on('click', function(e) {
			var mobileValue = $.trim($('input[name=mobile]').val());
			var verifycodeValue = $.trim($('input[name=mobile_vcode]').val());
			if (mobileValue == '') {
				qsToast({type:2,context: '请输入手机号码'});
				return false;
			}
			if (mobileValue != "" && !regularMobile.test(mobileValue)) {
				qsToast({type:2,context: '手机号码格式不正确'});
				return false;
			}
			if (verifycodeValue == '') {
				qsToast({type:2,context: '请输入手机验证码'});
				return false;
			}
			if (eval($('#verifyLogin').val())) {
				$('#doType').val('0'); // 通知极验登录
				window.captchaObj.refresh();
				$('#pop').show();
			} else {
				doAjax();
			}
		});

		/**
		 * 清空所填项
		 */
		$('.g-close').on('click', function() {
			$(this).next().val('');
		})
	</script>
</html>